﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using SocialFront.Entities;
using SocialFront.Providers.Blog;
using SocialFront.Providers.Relationship;

namespace SocialFront.Web.usercontrols.Blog
{
    public partial class MemberBlogList : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            IList<Member> members = RelationshipProvider.Provider.GetMemberRelatedToCurrentNode();
            List<Entities.Blog> blogs = new List<Entities.Blog>();
            if (members.Count != 0)
            {
                blogs = BlogProvider.Provider.GetBlogsByMember(members[0].Id);
            }else
            {
                // NOTE: this is a temp fix as the correct relationships done seem to be setup at the moment.
                members = RelationshipProvider.Provider.GetMemberRelatedToParentOfCurrentNode();
                if(members.Count!=0)
                    blogs = BlogProvider.Provider.GetBlogsByMember(members[0].Id);

            }
            lvBlogs.DataSource = blogs;
            lvBlogs.DataBind();
        }

        protected void lvBlogs_PagePropertiesChanging(object sender, PagePropertiesChangingEventArgs e)
        {
            this.ItemDataPager.SetPageProperties(e.StartRowIndex, e.MaximumRows, false);
            lvBlogs.DataBind();
        }
    }
}